<?php
/* ========================================
 * --------------------
 *  controller.php.php
 * --------------------
 * Created on 30.03.2010
 * ========================================
 * $Revision: $
 * $Author: Dmitry Boycov
 * $HeadURL: $ 
 * $Id: $
 * ========================================
 * Changes ["date: description (who)"]:
 *
 * 30.03.2010: Original version (WHo)
 * 16:21:58: Time 
 */
require_once("app/Controller.php");
require_once("modules/admin/AdminPage.php");
require_once("include/bd/DataBase.php");
require_once("include/bd/InsertQuery.php");

class AdminController extends Controller{

	public $key = 'admin';
    private $db = null;

	/**
	 * construct
	 * @return void
	 */
	public function __construct(){
		parent::__construct();
		$settings = App::settings();
		//check existence needed key in settings
		if(!in_array($this->key,$settings['module'])){
			$this->key = null;
		}

        $this->db = new DataBase($settings['db']['host'],$settings['db']['user'],$settings['db']['pwd'],$settings['db']['name']);
        $this->db->connect();
	}

	/**
	 * This action is default. And this action generate full page
	 * @return void
	 */
	public function action_execute(){
		$p = new AdminPage();
		if($this->key!=null){
            $p->show();
		}
	}

	public function action_createnewuser(){
		$name = App::request('name');
        $login = App::request('login');       
        if(!is_null($name) && !is_null($login)){
            $q = new InsertQuery('user', array("login"=>$name,"pasword"=>$login));
            $this->db->query($q);
        }
        echo '<span>success!!!</span>';
	}

    public function __destruct(){
       $this->db->close(); 
    }


}
?>